<?php

class wloginController extends base
{

    public function __construct()
    {
        parent::__construct('show');
    }

    /**
	 * qq 授权登录展示页面
	 * @return 
	 */
    public function doqq()
    {
        /*
            缺少防止恶意请求的方法
        */

        $this->view->assign('iswb', 0);
        $this->view->display('qqLogin');
    }
    /**
     * weibo 授权登录展示页面
     * @return 
     */
    public function doweibo()
    {
        /*
            缺少防止恶意请求的方法
        */

        $this->view->assign('iswb', 1);
        $this->view->display('qqLogin');
    }

    /*
     * 第三方授权登录中转页面
     */
    public function dooauth()
    {
        $type = common::request('type', 'G', '');

        $redirectUri = urlencode('http://irun.hupu.com/wlogin/OauthCode&type='.$type);
        $oauthUri = $this->load('wlogin')->getAuthUri($type, $redirectUri);

        common::go($oauthUri);
    }
    /*
     * 第三方授权登录 获取Authorization Code
     */
    public function doOauthCode()
    {
        $type = common::request('type', 'G', '');
        $code = common::request('code', 'G', '');
        $state = common::request('state', 'G', '');

        if($code != 'irun')
        {
            exit('error');
        }

        if($code)
        {
            $this->load('wlogin');
            $redirectUri = urlencode('http://irun.hupu.com/wlogin/getOauthCode&type='.$type);
            $access_token = $_ENV['wlogin']->getAccessToken($type, $code, $redirectUri);
            if($access_token)
            {
                $openid = $_ENV['wlogin']->getOpenId($type, $access_token);

                if($openid)
                {

                }
            }
        }
        
    }

}
